//
//  Datai6ViewController.m
//  Depressed.domo
//
//  Created by rimi on 16/5/31.
//  Copyright © 2016年 薛涛. All rights reserved.
//

#import "Datai6ViewController.h"

@interface Datai6ViewController ()

@end

@implementation Datai6ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self saveImageToSandBox];
}

- (void)saveImageToSandBox {
    /**获取沙盒路径*/
    /**主路径*/
    NSString *homeString = NSHomeDirectory();
    NSLog(@"沙盒路径：%@",homeString);
    
    /**document路径*/
    NSString *documentString = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject];
    NSLog(@"沙盒路径：%@",documentString);
    
    /**library路径*/
    NSString *librayString = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES)lastObject];
    NSLog(@"沙盒路径：%@",librayString);
    
    /**temp:临时路径*/
    NSString *tempString = NSTemporaryDirectory();
    NSLog(@"沙盒路径：%@",tempString);
    
    /**把图片存进沙盒*/
    /**保存图片的路径*/
    NSString *saveImagePath = [documentString stringByAppendingString:@"Steve Jobs"];
    /**获取图片*/
    NSString *path = [[NSBundle mainBundle]pathForResource:@"Steve Jobs" ofType:@"png"];
    UIImage *image = [UIImage imageWithContentsOfFile:path];
    /**图片转换data*/
    NSData *imageData = UIImagePNGRepresentation(image);
    NSFileManager *manage = [NSFileManager defaultManager];
    if (![manage fileExistsAtPath:saveImagePath]) {
        [manage createFileAtPath:saveImagePath contents:imageData attributes:nil];
    }
    /**读取文件*/
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:self.view.bounds];
    imageView.image = [UIImage imageWithContentsOfFile:saveImagePath];
    [self.view addSubview:imageView];
    /**删除沙盒文件*/
//    BOOL sucess = [manage removeItemAtPath:saveImagePath error:nil];
//    NSLog(@"是否删除成功%d",sucess);
}

@end
